package com.zsj.juc.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author zsj
 * @version 1.0
 * @date 2024/4/19 17:39
 * @description
 */
public class CompletionStageTest02 {
    public static void main(String[] args) {
        //thenAccept 消费处理 无返回结果
        //thenRun 不需要上一步的结果 也不会返回任何结果值
        CompletableFuture.supplyAsync(() -> {
            return ThreadLocalRandom.current().nextInt(5);
        }).thenApply(f -> {
            System.out.println(f);
            return f + 2;
        }).thenApply(f -> {
            return f + 3;
        }).thenRun(() -> {
        }).thenAccept(System.out::println);

        //下一步和上一步相依赖
        CompletableFuture.supplyAsync(() -> {
            return ThreadLocalRandom.current().nextInt(5);
        }).thenApply(f -> {
            System.out.println(f);
            return f + 2;
        }).thenApply(f -> {
            return f + 3;
        }).thenAccept(System.out::println);

    }
}
